package com.icss.flow.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.annotation.Primary;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @author WZG
 * @date 2024年04月12日 10:44
 */
@Slf4j
@Component
@Primary
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("start insert fill ....");
        this.strictInsertFill(metaObject, "createdOn", LocalDateTime.class, LocalDateTime.now());
        this.strictInsertFill(metaObject, "createdBy", String.class,"1");
        this.strictInsertFill(metaObject, "ownerUser", String.class, "1");
        this.strictInsertFill(metaObject, "ownerDepartment", String.class, "1");

    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("start update fill ....");
        this.strictUpdateFill(metaObject, "modifiedOn", LocalDateTime.class, LocalDateTime.now()); // 起始版本 3.3.0(推荐
    }
}